import 'package:flutter/foundation.dart';
import 'package:rxdart/rxdart.dart';
import 'package:loxen/api/api.dart';
import 'package:loxen/mode/base_mode.dart';
import 'package:loxen/mode/mine/user_follower_list.dart';

mixin UserFollowerMixin {
  //201为成功
  Stream<int> followerUser(String userId) {
    return ApiService.followUser(userId)
        .flatMap((value) => Stream.value(value.statusCode));
  }

  //200为取消成功
  Stream<int> unFollowerUser(String userId) {
    return ApiService.cancelFollow(userId)
        .flatMap((value) => Stream.value(value.statusCode));
  }

  Stream<FollowerList> userFollowerList(
      {String userId = '0', String page = '1', String pageSize}) {
    return ApiService.userFollowers(userId,page,pageSize)
        .flatMap((value) => compute(decodeFollowerList, value.data).asStream())
        .flatMap((value) => Stream.value(value.data));
  }

  static BaseMode<FollowerList> decodeFollowerList(dynamic json) {
    return BaseMode<FollowerList>(json);
  }
}
